package com.qhy.rabbitmq.service.impl;

import com.qhy.rabbitmq.service.SendService;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author qiuhongyu
 * @date 2021/2/23 14:43
 */
@Service("sendService")
public class SendServiceImpl implements SendService {

    //注入amqp的模板类，利用这个对象来发送和接收消息
    @Autowired
    private AmqpTemplate amqpTemplate;

    public void sendMessage(String message) {
        /**
         * 发送消息
         * 参数1 交换机的名字
         * 参数2 routingkey
         * 参数3 为要发送的消息数据
         */
        amqpTemplate.convertAndSend("bootDirectExchange", "bootDirectRoutingKey", message);
    }
}
